**Replicates CBSA-level specifications in DLM***
global dir = "C:\Users\MurphyD\Dropbox\GvtSpendingDebt\Replication\"

cd $dir
clear
set more off

******************************************************
 ***READ In Long Datasets
	use GvtDataCBSA.dta
	 keep if year<2014 & year>2001
	bysort year: egen spend_nat = sum(Spending)
	bysort year: egen oblig_nat = sum(dollars)

	*merge in GDP data...gdp0 is total (across industries) GDP
	merge 1:1 cbsa year using GDPbyMSAind, keepusing(cbsa year gdp0)
	drop _merge
	replace gdp0=gdp0*1e6
	
	 
	******Merge in Employment Data...emp0 and inc0 are total (across industries) employment and wage income
	 merge 1:1 cbsa year using QCEWannual.dta, keepusing(cbsa year inc0 emp0 inc928 emp928)
	 drop _merge
	 replace inc928=0 if inc928==.
	 replace emp928=0 if emp928==.
	 
	 
	 
	 ***dropping cities that don't have spending in each year.
	 gen HasSp=Spending<.
	 bysort cbsa: egen HasSpYears=sum(HasSp)
	 ta HasSpYears if year==2004
	 drop if HasSpYears<12
	 
	

*********************************************************
 
 ***Create Wide Dataset with values before (average 0607) and during (average 0809) recession
 
	merge m:1 cbsa using CBSAdebtWide
	drop _merge

	save temp, replace
	
	
	
	gen period=""
    replace period="0203" if inlist(year,2002,2003)
	replace period="0405" if inlist(year,2004,2005)
	replace period="0607" if inlist(year,2006,2007)
	replace period="0809" if inlist(year,2008,2009)

	rename dollarsobligated Obligated


	collapse (mean) Spending Obligated inc*  emp* gdp*   spend_nat oblig_nat, by(cbsa d2i2001 d2i2002 d2i2006 period )	
	drop if period==""
	
	reshape wide Spending Obligated inc*  emp* gdp*   spend_nat oblig_nat, i(cbsa) j(period) string 
	
	save TempWide, replace
	******************
	*now do inc, emp for 2007, 2009
	use temp, clear
	keep if inlist(year,2003,2005,2007,2009)
	keep cbsa year inc* emp* gdp*
	
	reshape wide  inc*  emp* gdp*  , i(cbsa) j(year)  
	
	merge 1:1 cbsa using TempWide
  drop _merge
	
	drop inc*0607 emp*0607 gdp*0607 inc*0809 emp*0809 gdp*0809 inc*0203 emp*0203 gdp*0203 inc*0405 emp*0405  gdp*0405 
***********************************************************************

*merge in Fracmil... 
merge 1:1 cbsa using fracmilCBSA
keep if _merge==3
drop _merge


 
  *Create Growth Variables
	gen Dspend_nat = (spend_nat0809 - spend_nat0607)
	gen Dob_nat=	(oblig_nat0809 - oblig_nat0607)	
	gen DpredictNS_ob = Dob_nat * fracmilOBNS/gdp02007
		gen DpredictNS_ObInc = Dob_nat * fracmilOBNS/inc02007
	gen DpredictNS_spend = Dspend_nat * fracmilNS/gdp02007
	gen DpredictNS_spendInc = Dspend_nat * fracmilNS/inc02007
	
	*Interaction terms
    gen DpredictNS_ObligIncDebt =DpredictNS_ObInc*d2i2006
    gen DpredictNS_ObligIncDebt01 =DpredictNS_ObInc*d2i2001

 
    gen DpredictNS_ObDebt =DpredictNS_ob*d2i2006
	gen DpredictNS_ObDebt01 =DpredictNS_ob*d2i2001

	gen DpredictNS_spend_debt = DpredictNS_spend*d2i2006
	gen DpredictNS_spendIncDebt =DpredictNS_spendInc*d2i2006
	gen DpredictNS_spend_debt01 = DpredictNS_spend*d2i2001
	gen DpredictNS_spendIncDebt01 =DpredictNS_spendInc*d2i2001
	
	gen DgOb=(Obligated0809-Obligated0607)/gdp02007
    gen DgOb_inc=(Obligated0809-Obligated0607)/inc02007
	gen DgSp=(Spending0809-Spending0607)/gdp02007
	gen DgSp_debt=DgSp*d2i2006
	gen DgSp_debt01=DgSp*d2i2001


	gen DgSp_inc=(Spending0809-Spending0607)/inc02007
	gen DgSp_incDebt=DgSp_inc*d2i2006
	gen DgSp_incDebt01=DgSp_inc*d2i2001

	gen DgOb_incDebt=DgOb_inc*d2i2006
	gen DgOb_debt=DgOb*d2i2006
	gen DgOb_incDebt01=DgOb_inc*d2i2001
	gen DgOb_debt01=DgOb*d2i2001

	gen Demp=(emp02009-emp02007)/emp02007
	gen Dgdp= (gdp02009-gdp02007)/gdp02007
	gen Dinc= (inc02009-inc02007)/inc02007
	

	gen Dinc928=(inc9282009-inc9282007)/inc02007
	gen Demp928=(emp9282009-emp9282007)/emp02007	


	la var DgOb "Change in dollars obligated (avg 08/09 minus avg06/07) relative to  GDP in 07"	
	la var DgSp "Change in DOD spending (avg 08/09 minus avg06/07) relative to  GDP in 07"	
	la var DgSp_inc "Change in DOD spending (avg 08/09 minus avg06/07) relative to income in 07"	
	la var DgOb_inc "Change in DOD obligations (avg 08/09 minus avg06/07) relative to income in 07"	
	la var Demp "Percent change in employment (09 relative to 07)"	
	la var Dinc "Percent change in income (09 relative to 07)"	
	la var Dgdp "Percent change in gdp(09 relative to 07) "
	
	*for Sum Stats
	gen Sp2I=Spending0607/inc02007
	
	
	****0203, 0405 variables**********************************************
	gen Dspend_nat0305 = (spend_nat0405 - spend_nat0203)
    gen Dob_nat0305=	(oblig_nat0405 - oblig_nat0203)	
	gen Dpredict_spend0305 = Dspend_nat0305 * fracmilNS/gdp02003
	gen Dpredict_ob0305 = Dob_nat0305 * fracmilOBNS/gdp02003
	gen Dpredict_spendInc0305 = Dspend_nat0305 * fracmilNS/inc02003
	gen Dpredict_ObInc0305 = Dob_nat0305 * fracmilOBNS/inc02003
	
 *Interaction terms
	gen Dpredict_spend_debt0305 = Dpredict_spend0305*d2i2002
	gen Dpredict_spendIncDebt0305 =Dpredict_spendInc0305*d2i2002
    gen Dpredict_ObligIncDebt0305 =Dpredict_ObInc0305*d2i2002
    gen Dpredict_ObligDebt0305 =Dpredict_ob0305*d2i2002

	gen DgOb0305=(Obligated0405-Obligated0203)/gdp02003
    gen DgOb_inc0305=(Obligated0405-Obligated0203)/inc02003
	gen DgSp0305=(Spending0405-Spending0203)/gdp02003
	gen DgSp_debt0305=DgSp0305*d2i2002

	gen DgSp_inc0305=(Spending0405-Spending0203)/inc02003
	gen DgSp_incDebt0305=DgSp_inc0305*d2i2002
	gen DgOb_incDebt0305=DgOb_inc0305*d2i2002
	gen DgOb_Debt0305=DgOb0305*d2i2002


	gen Demp0305=(emp02005-emp02003)/emp02003
	gen Dgdp0305= (gdp02005-gdp02003)/gdp02003
	gen Dinc0305= (inc02005-inc02003)/inc02003
	


*************************************************************************************

 *Merge in Other variables
 ***merge in industry employment shares
 merge 1:1 cbsa using IndEmpShare06
 drop _merge share*
  merge 1:1 cbsa using EmpShare02
 drop _merge 
 
 **merge in state 
 merge 1:1 cbsa using MapCBSAstate
 drop _merge

 
**************************************************
**Tables
merge 1:1 cbsa using DincMS 
drop _merge


**merge in MS covariates
 merge 1:1 cbsa using MSdataCBSA
 drop _merge
 
*Table 1: Summary Stats
tabstat Dinc DincNonTrad DincTrad DincConstr DincOther Demp  Dgdp Sp2I DgSp_inc DpredictNS_spendInc DgOb_inc DpredictNS_ObInc  d2i2006 if Demp<. , s(N mean sd min p5 p25 p50 p75 p95 max) column(statistics)


***T2 Bottom Panel***
quietly ivreg2  Dinc  (DgSp_inc = DpredictNS_spendInc)  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
 est store T21
 weakivtest 
 estadd scalar Fstat=r(F_eff)
 reg DgSp_inc  DpredictNS_spendInc whiteCBSA-urbanCBSA empshare1-empshare19
 mat b=e(b)
 estadd scalar FS=b[1,1]
quietly ivreg2  Dinc  (DgOb_inc = DpredictNS_ObInc)  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store T22
 weakivtest 
 estadd scalar Fstat=r(F_eff)
 reg DgOb_inc DpredictNS_ObInc empshare1-empshare19 whiteCBSA-urbanCBSA
  mat b=e(b)
  estadd scalar FS=b[1,1]
quietly ivreg2  Demp  (DgSp_inc = DpredictNS_spendInc)  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
 est store T23
 weakivtest 
 estadd scalar Fstat=r(F_eff)
  reg DgSp_inc DpredictNS_spendInc empshare1-empshare19 whiteCBSA-urbanCBSA
  mat b=e(b)
  estadd scalar FS=b[1,1]
quietly ivreg2  Demp (DgOb_inc = DpredictNS_ObInc)  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store T24
 weakivtest 
 estadd scalar Fstat=r(F_eff)
 reg DgOb_inc DpredictNS_ObInc empshare1-empshare19 whiteCBSA-urbanCBSA
   mat b=e(b)
  estadd scalar FS=b[1,1]
quietly ivreg2  Dgdp  (DgSp = DpredictNS_spend)  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
 est store T25
 weakivtest 
 estadd scalar Fstat=r(F_eff)
 reg DgSp DpredictNS_spend empshare1-empshare19 whiteCBSA-urbanCBSA
  mat b=e(b)
  estadd scalar FS=b[1,1]
quietly ivreg2  Dgdp  (DgOb = DpredictNS_ob)  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
 est store T26
 weakivtest 
 estadd scalar Fstat=r(F_eff)
 reg DgOb DpredictNS_ob empshare1-empshare19 whiteCBSA-urbanCBSA
   mat b=e(b)
   scalar FS=b[1,1]
  estadd scalar FS
estout  T2* using T2CBSA, drop(empshare* *CBSA) cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) stats(N r2 FS idstat idp  widstat Fstat, fmt(%9.0f %9.2f  %9.3f %9.3f %9.3f) labels("No. obs." "R.sq" "First Stage")) starlevels(* 0.1 ** 0.05 *** 0.01) replace  msign(--)  default(tex) modelwidth(8) varwidth(25)

***T2 Bottom Panel First Stage***
eststo:  quietly reg DgSp_inc  DpredictNS_spendInc whiteCBSA-urbanCBSA empshare1-empshare19
eststo:  quietly reg DgOb_inc DpredictNS_ObInc empshare1-empshare19 whiteCBSA-urbanCBSA
eststo:  quietly reg DgSp_inc DpredictNS_spendInc empshare1-empshare19 whiteCBSA-urbanCBSA
eststo:  quietly reg DgOb_inc DpredictNS_ObInc empshare1-empshare19 whiteCBSA-urbanCBSA
eststo:  quietly reg DgSp DpredictNS_spend empshare1-empshare19 whiteCBSA-urbanCBSA
eststo:  quietly reg DgOb DpredictNS_ob empshare1-empshare19 whiteCBSA-urbanCBSA
esttab using T2Panel2FirstStage.csv, p scalars( N  r2 idstat idp ) nocon sfmt(%4.2f) b(%5.3f) replace drop(empshare* *CBSA) 
eststo clear

***Table 3*** 
quietly ivreg2  Dinc  (DgSp_inc = DpredictNS_spendInc)  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A1	
quietly ivreg2  Dinc   d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A2
quietly ivreg2  Dinc  (DgSp_inc  = DpredictNS_spendInc ) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A3
quietly ivreg2  Dinc  (DgSp_inc DgSp_incDebt = DpredictNS_spendInc DpredictNS_spendIncDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A4
quietly ivreg2  Demp  (DgSp_inc = DpredictNS_spendInc)  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A5
quietly ivreg2  Demp   d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A6
quietly ivreg2  Demp  (DgSp_inc  = DpredictNS_spendInc ) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A7
quietly ivreg2  Demp  (DgSp_inc DgSp_incDebt = DpredictNS_spendInc DpredictNS_spendIncDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A8
quietly ivreg2  Dgdp  (DgSp = DpredictNS_spend)  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A9
quietly ivreg2  Dgdp   d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A10
quietly ivreg2  Dgdp  (DgSp  = DpredictNS_spend ) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A11
quietly ivreg2  Dgdp  (DgSp DgSp_debt = DpredictNS_spend DpredictNS_spend_debt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A12
estout  A* using Table3PanelA, drop(empshare* *CBSA) cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) stats(N r2 idstat idp  widstat , fmt(%9.0f %9.2f  %9.3f %9.3f %9.3f) labels("No. obs." "R.sq")) starlevels(* 0.1 ** 0.05 *** 0.01) replace  msign(--)  default(tex) modelwidth(8) varwidth(25)

quietly ivreg2  Dinc  (DgOb_inc = DpredictNS_ObInc)  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
  est store A1	
quietly ivreg2  Dinc   d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
  est store A2	
quietly ivreg2  Dinc  (DgOb_inc  = DpredictNS_ObInc ) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
  est store A3	
quietly ivreg2  Dinc  (DgOb_inc DgOb_incDebt = DpredictNS_ObInc DpredictNS_ObligIncDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
  est store A4	
quietly ivreg2  Demp (DgOb_inc = DpredictNS_ObInc)  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
  est store A5	
quietly ivreg2  Demp   d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
  est store A6	
quietly ivreg2  Demp  (DgOb_inc  = DpredictNS_ObInc ) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
  est store A7	
quietly ivreg2  Demp  (DgOb_inc DgOb_incDebt = DpredictNS_ObInc DpredictNS_ObligIncDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
  est store A8	
quietly ivreg2  Dgdp  (DgOb = DpredictNS_ob)  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A9	
quietly ivreg2  Dgdp   d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A10	
quietly ivreg2  Dgdp  (DgOb  = DpredictNS_ob ) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A11	
quietly ivreg2  Dgdp  (DgOb DgOb_debt = DpredictNS_ob DpredictNS_ObDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
  est store A12	
estout  A* using Table3PanelB, drop(empshare* *CBSA) cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) stats(N r2 idstat idp  widstat , fmt(%9.0f %9.2f  %9.3f %9.3f %9.3f) labels("No. obs." "R.sq")) starlevels(* 0.1 ** 0.05 *** 0.01) replace  msign(--)  default(tex) modelwidth(8) varwidth(25)




***Table 6***
foreach x in NonTradStrict NonTrad Tradable Const Other  {
quietly ivreg2 Dinc`x'  (DgSp_inc DgSp_incDebt = DpredictNS_spendInc DpredictNS_spendIncDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
est store Sp`x'
}
foreach x in  NonTradStrict NonTrad Tradable Const Other  {
quietly ivreg2 Dinc`x'  (DgOb_inc DgOb_incDebt = DpredictNS_ObInc DpredictNS_ObligIncDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
est store Ob`x'
}
estout  SpNonTradStrict SpNonTrad SpTradable SpConst SpOther ObNonTradStrict ObNonTrad ObTradable ObConst ObOther using Table6, drop(empshare* *CBSA) cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) stats(N r2 idstat idp  widstat , fmt(%9.0f %9.2f  %9.3f %9.3f %9.3f) labels("No. obs." "R.sq")) starlevels(* 0.1 ** 0.05 *** 0.01) replace  msign(--)  default(tex) modelwidth(8) varwidth(25)

***Table 7***
quietly ivreg2  Dinc928  (DgSp_inc = DpredictNS_spendInc)  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store NSsp
quietly ivreg2  Dinc928   d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store NSdebt
quietly ivreg2  Dinc928  (DgSp_inc  = DpredictNS_spendInc ) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store NSspdebt
quietly ivreg2  Dinc928  (DgSp_inc DgSp_incDebt = DpredictNS_spendInc DpredictNS_spendIncDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store NSspdebtInt
quietly ivreg2  Dinc928  (DgOb_inc = DpredictNS_ObInc)  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store NSob
quietly ivreg2  Dinc928   d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store NSdebt
quietly ivreg2  Dinc928  (DgOb_inc  = DpredictNS_ObInc ) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store NSobdebt
quietly ivreg2  Dinc928  (DgOb_inc DgOb_incDebt = DpredictNS_ObInc DpredictNS_ObligIncDebt) d2i2006  empshare1-empshare19 whiteCBSA-urbanCBSA , cluster(state)
 est store NSobdebtInt
estout  NSsp NSdebt NSspdebt NSspdebtInt NSob NSdebt NSobdebt NSobdebtInt using Table7, drop(empshare* *CBSA) cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) stats(N r2 idstat idp  widstat , fmt(%9.0f %9.2f  %9.3f %9.3f %9.3f) labels("No. obs." "R.sq")) starlevels(* 0.1 ** 0.05 *** 0.01) replace  msign(--)  default(tex) modelwidth(8) varwidth(25)



***Table8***
quietly ivreg2  Dinc0305  (DgSp_inc0305 = Dpredict_spendInc0305)  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre1
quietly ivreg2  Dinc0305   d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre2
quietly ivreg2  Dinc0305  (DgSp_inc0305  = Dpredict_spendInc0305 ) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre3
quietly ivreg2  Dinc0305  (DgSp_inc0305 DgSp_incDebt0305 = Dpredict_spendInc0305 Dpredict_spendIncDebt0305) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre4
quietly ivreg2  Demp0305  (DgSp_inc0305 = Dpredict_spendInc0305)  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre5
quietly ivreg2  Demp0305   d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre6
quietly ivreg2  Demp0305  (DgSp_inc0305  = Dpredict_spendInc0305 ) d2i2002 empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre7
quietly ivreg2  Demp0305  (DgSp_inc0305 DgSp_incDebt0305 = Dpredict_spendInc0305 Dpredict_spendIncDebt0305) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre8
quietly ivreg2  Dgdp0305  (DgSp0305 = Dpredict_spend0305)  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre9
quietly ivreg2  Dgdp0305   d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre10
quietly ivreg2  Dgdp0305  (DgSp0305  = Dpredict_spend0305 ) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre11
quietly ivreg2  Dgdp0305  (DgSp0305 DgSp_debt0305 = Dpredict_spend0305 Dpredict_spend_debt0305) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre12
 estout Pre* using Table8PanelA, drop(*empshare* *CBSA) cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) stats(N r2 idstat idp  widstat , fmt(%9.0f %9.2f  %9.3f %9.3f %9.3f) labels("No. obs." "R.sq")) starlevels(* 0.1 ** 0.05 *** 0.01) replace  msign(--)  default(tex) modelwidth(8) varwidth(25)

quietly ivreg2  Dinc0305  (DgOb_inc0305 = Dpredict_ObInc0305)  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre1
quietly ivreg2  Dinc0305   d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre2
quietly ivreg2  Dinc0305  (DgOb_inc0305  = Dpredict_spendInc0305 ) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre3
quietly ivreg2  Dinc0305  (DgOb_inc0305 DgOb_incDebt0305 = Dpredict_ObInc0305 Dpredict_spendIncDebt0305) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre4
quietly ivreg2  Demp0305  (DgOb_inc0305 = Dpredict_ObInc0305)  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre5
quietly ivreg2  Demp0305   d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre6
quietly ivreg2  Demp0305  (DgOb_inc0305  = Dpredict_ObInc0305 ) d2i2002 empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre7
quietly ivreg2  Demp0305  (DgOb_inc0305 DgOb_incDebt0305 = Dpredict_ObInc0305 Dpredict_spendIncDebt0305) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre8
quietly ivreg2  Dgdp0305  (DgOb0305 = Dpredict_ob0305)  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre9
quietly ivreg2  Dgdp0305   d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre10
quietly ivreg2  Dgdp0305  (DgOb0305  = Dpredict_ob0305 ) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre11
quietly ivreg2  Dgdp0305  (DgOb0305 DgOb_Debt0305 = Dpredict_ob0305 Dpredict_ObligDebt0305) d2i2002  empshare02_1-empshare02_19 whiteCBSA-urbanCBSA, cluster(state)
 est store Pre12
 estout Pre* using Table8PanelB, drop(*empshare* *CBSA) cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) stats(N r2 idstat idp  widstat , fmt(%9.0f %9.2f  %9.3f %9.3f %9.3f) labels("No. obs." "R.sq")) starlevels(* 0.1 ** 0.05 *** 0.01) replace  msign(--)  default(tex) modelwidth(8) varwidth(25)

 


save CBSAdataTemp, replace
*************************************************************************************************************


***Table 2 Panel A estimates
clear
use  CountyVars.dta
rename Dinc DincCounty
quietly ivreg2  DincCounty  (DgSp = DpredictNS_spend)   empshare1-empshare19 white-urban, cluster(state) first
 est store T2A1
 weakivtest 
 estadd scalar Fstat=r(F_eff)
quietly ivreg2  DincCounty  (DgOb= DpredictNS_ob)   empshare1-empshare19 white-urban, cluster(state) first 
 est store T2A2
 weakivtest 
 estadd scalar Fstat=r(F_eff)

eststo:  quietly reg DgSp  DpredictNS_spend empshare1-empshare19 white-urban, cluster(state)
eststo:  quietly reg DgOb  DpredictNS_ob empshare1-empshare19 white-urban, cluster(state)

*City
use CBSAdataTemp, clear
rename Dinc DincCBSA
rename Dgdp DgdpCBSA
ivreg2  DincCBSA  (DgSp_inc = DpredictNS_spendInc)   empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state) first 
 est store T2A3
 weakivtest 
 estadd scalar Fstat=r(F_eff)
ivreg2  DincCBSA  (DgOb_inc = DpredictNS_ObInc)   empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state) first 
 est store T2A4
 weakivtest 
 estadd scalar Fstat=r(F_eff)
 
eststo:  quietly reg DgSp_inc  DpredictNS_spendInc empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)
eststo:  quietly reg DgOb_inc  DpredictNS_ObInc empshare1-empshare19 whiteCBSA-urbanCBSA, cluster(state)

*State
use  StateVars.dta, clear
rename Dinc DincSTATE
quietly  ivreg2  DincSTATE (DgSp_inc  = DpredictNS_spendInc) white-urban empshare1-empshare19, first
 est store T2A5
 weakivtest 
 estadd scalar Fstat=r(F_eff)
quietly  ivreg2  DincSTATE (DgOb_inc  = DpredictNS_obInc) white-urban empshare1-empshare19, first
 est store T2A6
 weakivtest 
 estadd scalar Fstat=r(F_eff)
estout  T2A* using T2topPanel, drop(empshare* *CBSA *State white homevalmed vac owner educ* unemp pov urban) cells(b(star fmt(%9.3f)) t(par fmt(%9.2f))) stats(N r2 idstat idp  widstat Fstat, fmt(%9.0f %9.2f  %9.3f %9.3f %9.3f) labels("No. obs." "R.sq" )) starlevels(* 0.1 ** 0.05 *** 0.01) replace  msign(--)  default(tex) modelwidth(8) varwidth(25)

eststo:  quietly reg DgSp_inc  DpredictNS_spendInc white-urban empshare1-empshare19
eststo:  quietly reg DgOb_inc  DpredictNS_obInc white-urban empshare1-empshare19
esttab using T2Panel1FirstStage.csv, p scalars( N  r2 idstat idp ) nocon sfmt(%4.2f) b(%5.3f) replace drop(empshare* *CBSA *State white homevalmed vac owner educ* unemp pov urban) 
eststo clear

